﻿@model ScrumProject.ViewModels.TasksViewModel

@*@model IEnumerable<ScrumProject.Models.Task>*@

@{
    ViewBag.Title = "MyTasks";

    ScrumProject.Models.WorkMeasyrementRepository tr = new ScrumProject.Models.WorkMeasyrementRepository();
    ScrumProject.Models.WorkMeasurement wm = tr.GetMeasurementByUser(ViewBag.UserId);
}



<script type="text/javascript">
    function Work(userId,id, startTime,endTime,sub) {
        this.userId = userId;
        this.id = id;
        this.startTime = startTime;
        this.endTime = endTime;

    }


    $(document).ready(function () {
        $("#stopWork").hide();
        var ww = new Work();
        var things = JSON.stringify({ 'ww': ww });
        $.ajax({
            type: 'POST',
            dataType: 'json',
            url: '/smrpo6/Task/MeasureWorkBegin',
            contentType: 'application/json; charset=utf-8',
            data: things,
            success: function (dataCheck) {
                if (dataCheck == 'show') {
                    $("#stopWork").show();
                }
                else {
                    $("#stopWork").hide();

                }
            }

        });


        $(".btnStart").click(function () {
            var w = new Work();
            w.id = $(this).attr("id");
            w.startTime = new Date();
            var things = JSON.stringify({ 'w': w });
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/smrpo6/Task/MeasureWorkStart',
                contentType: 'application/json; charset=utf-8',
                data: things,
                success: function (dataCheck) {
                    if (dataCheck == 'ok') {
                        alert("work started");
                        $("#stopWork").show();
                    }
                    else {
                        alert("you are already working on task");

                    }
                }

            });

        });
        $("#stopWork").click(function () {
      
            var w = new Work();
            w.endTime = new Date();

            var things = JSON.stringify({ 'w': w });
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/smrpo6/Task/MeasureWorkStop',
                contentType: 'application/json; charset=utf-8',
                data: things,
                success: function (dataCheck) {
                    alert("work stopped");
                    $("#stopWork").hide();

                }


            });



        });
    });

</script>

<h2>My Tasks</h2>
<p>
   <input type="button" value="Stop working" class="btn" id="stopWork" />
</p>

<div style="height:auto; display:block; border:none; padding:1em 1.4em; background:none; 
        color:#4F4F4F;">

        @foreach (var item in Model.Tasks)
        {

            int stid = (int)item.StoryId;
            ScrumProject.Models.StoryRepository sr = new ScrumProject.Models.StoryRepository();
            ScrumProject.Models.Story story = sr.GetStory(stid);
            int projectId = (int)story.ProjectId;
            ScrumProject.Models.ProjectRepository pr = new ScrumProject.Models.ProjectRepository();
            ScrumProject.Models.Project project = pr.GetProject(projectId);

            String projectName = (String)project.Description;
            String storyName = (String)story.Name;
            <center>
        <div style="display:block; margin-top:0em; border:1px solid #CFCACC;  width:70%;">
            <div style="padding:5px 5px 8px; text-align:left;">
                <b>
                    @Html.DisplayFor(modelItem => storyName)
                </b>
                <br />
                <small>
                    @Html.DisplayFor(modelItem => story.Description)
                </small>
                <br />
            </div>
            
            <div style="background: #f6f6f6; margin-bottom: 10px; border: 1px solid #d0d0d0; border:none;
                text-align:left;">
                <ul style="margin-left:25px; margin-right:5px; display:block;">
                    <li style="line-height:28px; font:11px">
                        <div style="float:right; white-space:nowrap; display:block;">
                            @Html.ActionLink("Work history", "WorkHistory", new { id = item.Id })
                            <input type="button"  value="Start working" class="btnStart" id="@item.Id"/>
                        </div>
                        @if (item.Status.Equals(3))
                        { 
                            <label style="color:#65C429; font-size:small">(Completed)</label>
                        }
                        @Html.DisplayFor(modelItem => item.Description)
                        <small> (
                        @Html.ActionLink("Relase task", "ReleaseTask", new { id = item.Id })
                        ) </small>
                    </li>
                </ul>
            </div>
            
        </div>
            <br />
             </center>
        }
</div>

@*<center>
<table class="table" style="width:70%; border: 1px solid #CFCACC;">
    <tr>
        <th>
            Story Name
        </th>
        <th>
            Task Description
        </th>
        <th>
            Work Remaining
        </th>
        <th></th>
        <th></th>
         <th>
            
        </th>
    </tr>
   @foreach (var item in Model.Tasks) {

        int stid = (int)item.StoryId;
        ScrumProject.Models.StoryRepository sr = new ScrumProject.Models.StoryRepository();
        ScrumProject.Models.Story story = sr.GetStory(stid);
        int projectId = (int)story.ProjectId;
        ScrumProject.Models.ProjectRepository pr = new ScrumProject.Models.ProjectRepository();
        ScrumProject.Models.Project project = pr.GetProject(projectId);
        
        String projectName = (String)project.Description;
        String storyName = (String)story.Name;
        
        <tr>
            <td><center>@Html.DisplayFor(modelItem => storyName)</center></td>
            <td><center>
                @if (item.Status.Equals(3)) { 
                    <label style="color:#65C429; font-size:small">(Completed)</label>
                    @Html.DisplayFor(modelItem => item.Description)
                }
                else{
                @Html.DisplayFor(modelItem => item.Description)}
                
            </center></td>
            <td><center>@Html.DisplayFor(modelItem => item.WorkRemaining)</center></td>
            <td><center>@Html.ActionLink("Relase task", "ReleaseTask", new { id = item.Id })</center></td>
            <td><center>@Html.ActionLink("Work history", "WorkHistory", new { id = item.Id })</center></td>
            <td><center><input type="button"  value="Start working" class="btnStart" id="@item.Id"  /></center></td>
            
        </tr>
    }
</table>
</center>*@
<div>
    @Html.ActionLink("Back to First Page", "Index", "", new { projectId = ViewBag.projectId }, null)
</div>
